<template>
  <div class="ssb" :class="{ 'is-show': isShow }">
    <div class="ssb-container">
      <div class="lb-chat-left-btn" @click="clear()">
        <i class="el-icon-plus"></i>创建{{ title }}
      </div>
      <!-- <div v-if="list.length > 0 && title == '审稿'" class="lb-chat-left-lists">
        <div class="lb-chat-left-lists-li is-active">
          <div class="lb-chat-left-li-name">
            <span class="ellipsis lb-chat-left-li-name-txt">稿子1 </span>
            <i class="el-icon-delete"></i>
          </div>
        </div>
      </div> -->

      <div
        v-if="
          list.length > 0 &&
          (title == '对话' ||
            title == '绘画' ||
            title == '报告' ||
            title == 'PPT' ||
            title == '总结' ||
            title == '审稿' ||
            title == '翻译')
        "
        class="lb-chat-left-lists"
      >
        <div v-for="(message, index) in list" :key="index">
          <div
            class="lb-chat-left-lists-li"
            :class="{ 'is-active': message.id == id }"
          >
            <div class="lb-chat-left-li-name">

              <span
                v-if="message.syncstatus == '00'"
                class="ellipsis lb-chat-left-li-name-txt"
                aria-disabled="message.syncstatus == '00'"
                >{{ message.fromtext }}
              </span>

              <span v-else
                class="ellipsis lb-chat-left-li-name-txt"
                aria-disabled="message.syncstatus == '00'"
                @click="changeChat(message)"
                >{{ message.fromtext }}
              </span>
              <i
                v-if="message.id == id && message.syncstatus == '01'"
                class="el-icon-delete"
                @click="del(message)"
              ></i>
              <!-- <i
                class="el-icon-delete"
                @click="del(message)"
              ></i> -->
              <i
                v-if="message.syncstatus == '00'"
                class="el-icon-loading"
              ></i>
            </div>
          </div>
        </div>
      </div>

      <div
        v-if="list.length > 0 && title == '翻译11'"
        class="lb-chat-left-lists"
      >
        <div v-for="(message, index) in list" :key="index">
          <div
            class="lb-chat-left-lists-li"
            :class="{ 'is-active': message.id == id }"
          >
            <div class="lb-chat-left-li-name">
              <span
                class="ellipsis lb-chat-left-li-name-txt"
                @click="changeChat(message)"
                >{{ message.id }}
              </span>
              <i
                v-if="message.id == id"
                class="el-icon-delete"
                @click="del(message)"
              ></i>
            </div>
          </div>
        </div>
      </div>
      <!-- <div v-if="list.length > 0 && title == '对话'" class="lb-chat-left-lists">
        <div v-for="(message, index) in list" :key="index">
          <div class="lb-chat-left-lists-li is-active">
            <div class="lb-chat-left-li-name">
              <span
                class="ellipsis lb-chat-left-li-name-txt"
                @click="changeChat(message)"
                >{{ message.fromtext }}
              </span>
              <i class="el-icon-delete" @click="del(message)"></i>
            </div>
          </div>
        </div>
      </div> -->
      <div v-if="list.length == 0" class="empty">
        <img src="@/assets/imgs/academic-empty.png" alt="" />
        <div class="ssb-msg">暂时还没有历史记录哦，<br />快去创建第一条吧~</div>
      </div>
    </div>
    <div class="ssb-eh" @click="isShow = !isShow">
      <div class="ssb-eh__close">
        <i v-if="isShow" class="el-icon-arrow-left"></i>
        <i v-else class="el-icon-arrow-right"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "LeftSider",
  props: {
    title: {
      type: String,
      default: "",
    },
    id: {
      type: Number,
      default: 0,
    },
    list: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      isShow: true,
    };
  },
  methods: {
    changeChat(message) {
      this.$emit("transmit", message);
    },
    del(message) {
      this.$emit("del", message);
    },
    clear() {
      this.$emit("clear", "");
    },
  },
};
</script>

<style lang="less" scoped>
.ssb {
  display: flex;
  height: 100%;
  width: 0;
  background: #ffffff;
  z-index: 10;
  position: relative;
  transition: width 0.2s;
  &.is-show {
    width: 270px;
  }
  .ssb-container {
    width: 100%;
    overflow: hidden;
    box-shadow: 2px 0 12px 1px #0000000f;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 270px;
    .lb-chat-left-btn {
      padding: 10px 12px;
      color: #fff;
      cursor: pointer;
      border: 1px solid #4d4d4f;
      border-radius: 8px;
      margin: 20px 20px 8px;
      background-color: #0d0f10;
      text-align: center;
      .el-icon-plus {
        margin-right: 10px;
        font-size: 16px;
      }
    }
    .empty {
      margin-top: 20px;
      flex: 1 1;
      padding: 0 12px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      img {
        width: 132px;
        height: 132px;
      }
      .ssb-msg {
        font-size: 12px;
        font-weight: 400;
        color: #8c8c8c;
        text-align: center;
        line-height: 20px;
        margin-top: 10px;
      }
    }
    .lb-chat-left-lists {
      margin-top: 20px;
      height: 0;
      flex: 1 1;
      padding: 0 12px;
      overflow-y: auto;
      .lb-chat-left-lists-li {
        color: #141414;
        padding: 12px;
        cursor: pointer;
        margin-bottom: 5px;
        border-radius: 8px;
        position: relative;
        .lb-chat-left-li-name {
          display: flex;
          align-items: center;
          justify-content: space-between;
          .lb-chat-left-li-name-txt {
            width: 80%;
            padding: 0 6px;
          }
        }
        .lb-chat-left-li-name-btns {
          position: absolute;
          right: 12px;
          .il {
            font-size: 14px;
            margin-right: 4px;
          }
          .ir {
            font-size: 14px;
            margin-left: 10px;
            margin-right: 4px;
          }
        }
        &.is-active {
          background: #eee;
        }
      }
    }
  }
  .ssb-eh {
    position: absolute;
    left: 100%;
    top: 62px;
    .ssb-eh__close {
      width: 20px;
      text-align: center;
      line-height: 32px;
      background: #ffffff;
      box-shadow: 4px 0 16px 1px #3634651a;
      border-radius: 0 6px 6px 0;
      border: 1px solid #e5e5e5;
      border-left: none;
      cursor: pointer;
      color: #141414;
    }
  }
}
</style>
